﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using ToolsLayer;
using System.Data;

namespace Webcar.UI
{
    public partial class RecentCars : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.IsPostBack) return;
                string sql = @"select top 14 a.* from v_bs_car_record a 
            where a.is_use ='T' and a.dept_delflag='F' and a.dept_code in 
            (select dept_code from bs_man_dept where man_code='{0}')
            and (a.child_dept in (select child_dept from bs_man_childdept where userid='{0}') or a.child_dept is null or a.child_dept='') order by buy_date desc";
                sql = string.Format(sql, CurrentUser.LoginUserID);
                if (CurrentUser.IsSuperUser())
                {
                    sql = @"select top 14 a.* from v_bs_car_record a 
                            where a.is_use ='T' and a.dept_delflag='F'  order by buy_date desc";
                }
                
                this.Repeater1.DataSource = DB.ExecuteDataset(sql);
                this.Repeater1.DataBind();
            }
            catch (Exception ex)
            {
                new CurrentUser().LogError(ex);
            }
        }
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink link = (HyperLink)e.Item.FindControl("hyperlink1");
            DataRowView row = e.Item.DataItem as DataRowView;
            string xh = row["car_NO"].ToString();
            Label newlabel = (Label)e.Item.FindControl("newlabel");

            InfoChecker ic = new InfoChecker();
            newlabel.Visible = !ic.InfoIsRead(xh, InfoCheckType.Car);

            string url = "car/CarView.aspx?carno=" + xh;
            link.NavigateUrl = "javascript:openDialog('"+url+"',620,380);";
        }
    }
}